/* $RCSFile: ADNDynKbArticle.cs $
 * Apache license v2 2011 by Christian Surieux
 * $Source: ?/CRMWrapper3/DynEntities/ADNDynKbArticle.cs $
 * $log$
 * Revision 19 2010/10/02 14:01:49  christian.surieux
 *   Corrected a bug in allmost everyADNDyn file for PrimaryFieldVualue
 * Revision 6 2010/08/06 19:56:33  christian.surieux
 *   Added Log to All cs files
 */

using System;
using System.Diagnostics;
using System.Collections;
using System.ComponentModel;
using System.Collections.Generic;
using System.Text;
using CrmSdk;

namespace AddonNice.CRMWrapper
{
	public class ADNDynKbArticle : DynEntity
	{
        protected class Ftor: DFactor
        {
            public Ftor() : base(CrmStr.kbarticle)
            {}

            public override Type DynType
            { get { return typeof(ADNDynKbArticle); } }

            public override string DynTypename
            {   get{ return CrmStr.kbarticle;}}

            public override DynEntity Build()
            {   return new ADNDynKbArticle();}

            public override DynEntity Build(CRMWrapperBase w, InternalDynamicEntity dEntity, PropertyDescriptorCollection wproperties)
            {   return new ADNDynKbArticle(w, dEntity, wproperties, null);}

            public override DynEntity Build(CRMWrapperBase w, string PrimaryFieldValue)
            {   return new ADNDynKbArticle(w,PrimaryFieldValue);}

            public override DynEntity Build(CRMWrapperBase w,Guid PrimaryKeyValue)
            {   return new ADNDynKbArticle(w,PrimaryKeyValue);}
        }

        static ADNDynKbArticle(){new Ftor();} 

        public override bool HasOwnerProperty
        {
            get
            {
                return false;
            }
        }

        public override bool HasBusinessUnitProperty
        {
            get
            {
                return false;
            }
        }

        public ADNDynKbArticle(): base()
		{}

        public ADNDynKbArticle(CRMWrapperBase w, string PrimaryFiedlValue)
			: base(w,CrmStr.kbarticle)
		{
            if ( PrimaryFiedlValue != string.Empty )
                title    =   PrimaryFiedlValue;
		}

		public ADNDynKbArticle(CRMWrapperBase w, Guid CrmId)
			: base(w,CrmStr.kbarticle, CrmId)
		{}

		public ADNDynKbArticle(CRMWrapperBase w, InternalDynamicEntity e)
			: base(w,CrmStr.kbarticle,e,null,null)
		{}

		public ADNDynKbArticle(CRMWrapperBase w, InternalDynamicEntity e,PropertyDescriptorCollection prop,InternalColumnSet s)
			: base(w,CrmStr.kbarticle,e,prop,s)
		{}

        public ADNDynKbArticle(ResetWrapperHandler fn, string PrimaryFiedlValue)
			: base(fn,CrmStr.kbarticle)
		{
            if ( PrimaryFiedlValue != string.Empty )
                title    =   PrimaryFiedlValue;
		}

		public ADNDynKbArticle(ResetWrapperHandler fn, Guid CrmId)
			: base(fn,CrmStr.kbarticle, CrmId)
		{}

		public ADNDynKbArticle(ResetWrapperHandler fn, InternalDynamicEntity e)
			: base(fn,CrmStr.kbarticle,e,null,null)
		{}

		public ADNDynKbArticle(ResetWrapperHandler fn, InternalDynamicEntity e,PropertyDescriptorCollection prop,InternalColumnSet s)
			: base(fn,CrmStr.kbarticle,e,prop,s)
		{}
		
        /// <summary>
		/// Crm Key
		/// </summary>
        [CrmDynAttribute(CrmStr.kbarticle)]
        public Guid kbarticleid
		{
			get
			{
				return KeyPropertyValue(CrmStr.kbarticleid);
			}
			set
			{
				AddKeyProperty(CrmStr.kbarticleid, value);
			}
		}

        protected override void SetCrmIdProperty(Guid crmId)
        {
           if ( !dicProperty.ContainsKey(CrmStr.kbarticleid) || KeyPropertyValue(CrmStr.kbarticleid) != crmId )
                kbarticleid   =   crmId;
        }
        
        public override string PrimaryFieldName
        {
            get
            {
               return CrmStr.title;
            }
           set
           {}
        }

        /// <summary>
        /// Value contained in the PrimaryField for the DynEntity or empty if no PrimaryField
        /// </summary>
        public override string PrimaryFieldStringValue
        {
            get
            {
                return title;
            }
            set
            {
                title =   value;
            }
        }

        public override Guid PrimaryKeyGuidValue
        {
           get
           {
                return kbarticleid;
           }
           set
           {
               kbarticleid    =   value;
           }
        }

        /// <summary>
        /// Gets or sets the title of the subject. 
        /// </summary>
        [CrmDynAttribute(CrmStr.kbarticle)]
        public string title 
        {
            get
            {
                return StringPropertyValue(CrmStr.title);
            }
            set
            {
                AddStringProperty(CrmStr.title,value);
            }
        }

        /// <summary>
        /// Contains the description of the subject. 
        /// </summary>
        [CrmDynAttribute(CrmStr.kbarticle)]
        public string description 
        {
            get
            {
                return StringPropertyValue(CrmStr.description);
            }
            set
            {
                AddStringProperty(CrmStr.description,value);
            }
        }

        /// <summary>
        /// Gets or sets the ID of the subject associated with the knowledge base article 
        /// </summary>
        [CrmDynAttribute(CrmStr.kbarticle)]
        public Guid subjectid
        {
            get
            {
                if (ContainsKey(CrmStr.subjectid))
                    return LookupPropertyValue(CrmStr.subjectid);
                return Guid.Empty;
            }
            set
            {
                AddLookupProperty(CrmStr.subjectid,CrmStr.subject,value);
            }
        }

        [CrmDynAttribute(CrmStr.kbarticle)]
        public string subjectName
        {
            get
            {
                if (ContainsKey(CrmStr.subjectid))
                    return LookupPropertyName(CrmStr.subjectid);
                return string.Empty;
            }
        }
        
        /// <summary>
        /// Gets the knowledge base article number. 
        /// </summary>
        [CrmDynAttribute(CrmStr.kbarticle)]
        public int number
        {
            get
            {
                if ( ContainsKey(CrmStr.number) )
                    return NumberPropertyValue(CrmStr.number);
                return 0;
            }
            set
            {
                AddNumberProperty(CrmStr.number,value);
            }
        }

        /// <summary>
        /// Gets or sets XML data for the knowledge base article
        /// </summary>
        [CrmDynAttribute(CrmStr.kbarticle)]
        public string articlexml 
        {
            get
            {
                return StringPropertyValue(CrmStr.articlexml);
            }
            set
            {
                AddStringProperty(CrmStr.articlexml,value);
            }
        }

        /// <summary>
        /// Gets or sets comments regarding the knowledge base article. 
        /// </summary>
        [CrmDynAttribute(CrmStr.kbarticle)]
        public string comments 
        {
            get
            {
                return StringPropertyValue(CrmStr.comments);
            }
            set
            {
                AddStringProperty(CrmStr.comments,value);
            }
        }

        /// <summary>
        /// Gets a description of the content of the knowledge base article. 
        /// </summary>
        [CrmDynAttribute(CrmStr.kbarticle)]
        public string content 
        {
            get
            {
                return StringPropertyValue(CrmStr.content);
            }
            set
            {
                AddStringProperty(CrmStr.content,value);
            }
        }

        /// <summary>
        /// Gets or sets the keywords to be used for searches in knowledge base articles. 
        /// </summary>
        [CrmDynAttribute(CrmStr.kbarticle)]
        public string keywords 
        {
            get
            {
                return StringPropertyValue(CrmStr.keywords);
            }
            set
            {
                AddStringProperty(CrmStr.keywords,value);
            }
        }
        
        [CrmDynAttribute(CrmStr.kbarticle)]
        public Guid kbarticletemplateid
        {
            get
            {
                if (ContainsKey(CrmStr.kbarticletemplateid))
                    return LookupPropertyValue(CrmStr.kbarticletemplateid);
                return Guid.Empty;
            }
            set
            {
                AddLookupProperty(CrmStr.kbarticletemplateid,CrmStr.kbarticletemplate,value);
            }
        }

        [CrmDynAttribute(CrmStr.kbarticle)]
        public string kbarticletemplateName
        {
            get
            {
                if (ContainsKey(CrmStr.kbarticletemplateid))
                    return LookupPropertyName(CrmStr.kbarticletemplateid);
                return string.Empty;
            }
        }
    }
}
